from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from media.models import VideoStream, Media


class VideoStreamSerializer(ModelSerializer):
    class Meta:
        model = VideoStream
        fields = '__all__'


class MediaSerializer(ModelSerializer):
    class Meta:
        model = Media
        fields = '__all__'


class MediaListSerializer(ModelSerializer):
    video_type = serializers.SerializerMethodField(help_text='视频类型')
    license_number = serializers.SerializerMethodField(help_text='车牌号')

    class Meta:
        model = Media
        fields = ['id', 'uri', 'start_time', 'license_number', 'video_type', 'channel_id']

    def get_video_type(self, obj):
        return obj.video_type

    def get_license_number(self, obj):
        return obj.license_number
